package com.spzx.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.spzx.common.core.constant.UserConstants;
import com.spzx.common.core.utils.StringUtils;
import com.spzx.product.domain.Brand;
import com.spzx.product.mapper.BrandMapper;
import com.spzx.product.service.BrandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 分类品牌 服务实现类
 * </p>
 *
 * @author lynn
 * @since 2025-03-12
 */
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {

    @Autowired
    private BrandMapper brandMapper;

    @Override
    public List<Brand> selectBrandListByName(String name) {
            List<Brand> brandList = brandMapper.selectList(new LambdaQueryWrapper<Brand>().like(Brand::getName, name));
            return brandList;
    }

    @Override
    public boolean checkBrandNameUnique(Brand brand) {
        Long brandId = StringUtils.isNull(brand.getId()) ? -1L : brand.getId();
        Brand info = brandMapper.checkBrandNameUnique(brand.getName());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != brandId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }


}
